<template>
	<div >
		<el-card shadow="hover">
			<div class=" mb15">
				
				<el-row :gutter="10" class="mb8">
					<el-col :span="1.5">
						<el-button type="primary" @click="handleAdd"  v-if="permissionStore.isPermissionsBtn('009003001')"
							><el-icon><Plus /></el-icon>新增</el-button
						>
					</el-col>
				</el-row>
			</div>
			<el-table v-loading="loading" :data="tableData.data">
				<el-table-column label="收款户名" align="center" prop="accountName" min-width="100px" />
				<el-table-column label="收款银行" align="center" prop="bankName" min-width="100px" />
				<el-table-column label="收款银行账户" align="center" prop="accountNumber" min-width="100px" />
				<el-table-column label="状态" align="center" min-width="100px" >
					<template #default="scope" >
						<el-tag :type="scope.row.states?'success':'danger'" >{{ scope.row.states?'启用':'禁用' }}</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="创建时间" align="center"  min-width="150px">
					<template #default="scope" >{{ formatDateTime(scope.row.createTime) }}</template>
				</el-table-column>
				<el-table-column label="创建人" align="center" prop="createBy" min-width="100px"/>
				<el-table-column label="操作" align="center" class-name="small-padding" min-width="200px" fixed="right" v-if="permissionStore.isPermissionsBtn(['009003002','009003003'])">
					<template #default="scope">
						<el-button type="primary" link @click="handleUpdate(scope.row)" v-if="permissionStore.isPermissionsBtn('009003002')"
							><el-icon><EditPen /></el-icon>修改</el-button
						>
						<el-button type="danger" link @click="handleDelete(scope.row)" v-if="permissionStore.isPermissionsBtn('009003003')"
							><el-icon><DeleteFilled /></el-icon>删除</el-button
						>
					</template>
				</el-table-column>
			</el-table>
			<pagination
				v-show="tableData.total > 0"
				:total="tableData.total"
				v-model:page="tableData.param.pageNumber"
				v-model:limit="tableData.param.pageLength"
				@pagination="getList"
			/>
		</el-card>
		<addView ref="addRef" @getList="getList"></addView>
		<editView ref="editRef" @getList="getList"></editView>
	</div>
</template>
<script lang="ts">
import { accountListApi ,delAccountApi} from '@/api/financeCenter/proceedsAccountSet';
import { toRefs, reactive, onMounted, ref, defineComponent, computed, getCurrentInstance, toRaw } from 'vue';
import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
import addView from './component/add.vue';
import editView from './component/edit.vue';
import {formatDateTime} from "@/utils/index"
import { usePermissionStore } from "@/store/modules/permission"
export default defineComponent({
	name: 'proceedsAccountSetList', //收款账户设置
	components: {
		addView,
		editView,
	},
	setup() {
		const { proxy } = <any>getCurrentInstance();
		const loading = ref(false);
		const queryRef = ref();
		const addRef = ref();
		const editRef = ref();
		const permissionStore = usePermissionStore()
		const state = reactive({
			tableData: {
				data: [],
				total: 0,
				param: {
					pageNumber: 1,
					pageLength: 10,
				},
			},
		});
		// 页面加载时
		onMounted(() => {
			initTableData();
		});
		// 初始化表格数据
		const initTableData = () => {
			getList();
		};
		/** 重置按钮操作 */
		const resetQuery = (formEl: FormInstance | undefined) => {
			if (!formEl) return;
			formEl.resetFields();
			getList();
		};
		// 获取列表数据
		const getList = () => {
			loading.value = true;
			accountListApi(state.tableData.param).then((res: any) => {
				let list = res.data.list ?? [];
				state.tableData.data = list;
				console.log(state.tableData.data);
				state.tableData.total = res.data.total;
				loading.value = false;
			});
		};
		
		const handleAdd = () => {
			addRef.value.openDialog();
		};
		const handleUpdate = (row) => {
			editRef.value.openDialog(toRaw(row));
		};
		const handleDelete = (row) => {
			let msg = `此操作将永久删除收款账户:${row.accountName}，是否继续?`
			ElMessageBox.confirm(msg, '提示', {
				confirmButtonText: '确认',
				cancelButtonText: '取消',
				type: 'warning',
			})
				.then(() => {
					delAccountApi({id:row.id}).then(() => {
						ElMessage.success('删除成功');
						getList();
					});
				})
				.catch(() => {});
		};
		
		return {
			proxy,
			addRef,
			editRef,
			loading,
			queryRef,
			resetQuery,
			getList,
			handleAdd,
			handleUpdate,
			handleDelete,
			formatDateTime,
			permissionStore,
			...toRefs(state),
		};
	},
});
</script>
<style lang="scss" scoped>
.colBlock {
	display: block;
}
.colNone {
	display: none;
}
</style>
